package com.slipper.sfts.member.service;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;

import com.slipper.sfts.member.dao.MemberAccountDao;
import com.slipper.sfts.api.member.bo.MemberAccountBO;

import com.slipper.common.transaction.ReadTransactional;
import com.slipper.common.transaction.WriteTransactional;
import com.slipper.common.util.Tool;

@Service
@ReadTransactional
public class MemberAccountService {
    @Resource
    private MemberAccountDao memberAccountDao;
    
    public MemberAccountBO queryBy(String id) {
        return memberAccountDao.queryBy(id);
    }
    
    public List<MemberAccountBO> queryList(MemberAccountBO bo) {
        return memberAccountDao.queryList(bo);
    }
    
    public PageInfo<MemberAccountBO> queryPage(MemberAccountBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(memberAccountDao.queryList(bo));
    }
    
    @WriteTransactional
    public int save(MemberAccountBO bo) {
        if (bo.getId() != null && !"".equals(bo.getId())) {
            return memberAccountDao.update(bo);
        } else {
            bo.setId(Tool.getUUID());
            return memberAccountDao.insert(bo);
        }
    }
    
    @WriteTransactional
    public int delete(MemberAccountBO bo) {
        return memberAccountDao.delete(bo);
    }
}
